<?php

/**
 * 供应商订单行为日志处理
 */
namespace App\Service\OrderService;

use App\Service\BaseService;
use App\Amqp\Producer\OrderLogMessageProducer;
use Hyperf\Amqp\Producer;
use App\Service\Code\Normal;

class OrderSupplierEventLogMessageService extends BaseService
{
    //类型（1-创建订单,2-订单支付，3-订单取消，4-订单售后申请，5-订单售后取消，6-订单售后审核拒绝，7-订单售后通过,8-订单更新物流，9-订单推送成功，10-订单推送失败，11-确认收货,12-支付单发起申报,13-支付单申报结果回调
    //14-订单发起申报，15-订单申报结果回调,16-进入结算,17-订单更新基础信息，18-订单发货
    const EVENT_TYPE_ORDER_CREATE                   = 1;
    const EVENT_TYPE_ORDER_PAY                      = 2;
    const EVENT_TYPE_ORDER_CANCEL                   = 3;
    const EVENT_TYPE_ORDER_AFTER_SALE_APPLY         = 4;
    const EVENT_TYPE_ORDER_AFTER_SALE_CANCEL        = 5;
    const EVENT_TYPE_ORDER_AFTER_SALE_REJECT        = 6;
    const EVENT_TYPE_ORDER_AFTER_SALE_PASS          = 7;
    const EVENT_TYPE_ORDER_PUSH_SUPPLIER_PASS       = 9;
    const EVENT_TYPE_ORDER_PUSH_SUPPLIER_FAIL       = 10;
    const EVENT_TYPE_ORDER_SHIPPING_RECEIVE         = 11;
    const EVENT_TYPE_ORDER_PAY_DECLARE_APPLY        = 12;
    const EVENT_TYPE_ORDER_PAY_DECLARE_APPLY_NOTIFY = 13;
    const EVENT_TYPE_ORDER_DECLARE_APPLY            = 14;
    const EVENT_TYPE_ORDER_DECLARE_APPLY_NOTIFY     = 15;
    const EVENT_TYPE_ORDER_SETTLEMENT_PAY           = 16;
    const EVENT_TYPE_ORDER_BASEINFO_MODIFY          = 17;
    const EVENT_TYPE_ORDER_SHIPPING                 = 18;
    const EVENT_TYPE_ORDER_SETTLEMENT_AFTERSALE     = 19;
    
    /**
     * 添加行为日志表
     * @param string $order_supplier_id
     * @param int $order_mode
     * @param string $contents
     * @param int $system_user_id
     * @param string $system_user_name
     */
    public function publish( string $order_supplier_id,int $order_mode,string $contents,int $system_user_id = 0, string $system_user_name = '')
    {
        $MessageBody = [
            'order_supplier_id'     =>  $order_supplier_id,
            'order_mode'            =>  $order_mode,
            'contents'              =>  $contents,
            'system_user_id'        =>  $system_user_id,
            'system_user_name'      =>  $system_user_name,
        ];
        $publishMsg = json_encode($MessageBody,JSON_UNESCAPED_UNICODE);
        try {
            $handlerMessage = new OrderLogMessageProducer($MessageBody);
            $producer = container()->get(Producer::class);
            $result = $producer->produce($handlerMessage,true);
            if( $result ) {
                return Normal::returnCode(Normal::SUC,"发布成功");
            }
            return Normal::returnCode(Normal::FAIL,"操作失败，请稍微再试[100000]");
        } catch ( \Throwable $e ) {
            return Normal::returnCode(Normal::FAIL,"操作失败，请稍微再试[{$e->getMessage()},{$e->getLine()},{$e->getFile()}]");
        }
    }
}